package com.offcn.sellergoods.controller;

import com.offcn.entity.Result;
import com.offcn.entity.StatusCode;
import com.offcn.sellergoods.pojo.ItemCat;
import com.offcn.sellergoods.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/itemCat")
public class ItemCatController {

    @Autowired
    private ItemCatService itemCatService;

    @GetMapping("/parent/{parentId}")
    public Result<List<ItemCat>> findByParentId(@PathVariable Long parentId){
        List<ItemCat> itemCatList = itemCatService.findByParentId(parentId);
        return new Result<>(true, StatusCode.OK,itemCatList,"根据父级分类的Id查询子分类成功");
    }

    @GetMapping("/{id}")
    public Result<ItemCat> findById(@PathVariable Long id){
        ItemCat itemCat = itemCatService.findById(id);
        return new Result<>(true,StatusCode.OK,itemCat,"根据Id获取分类成功");
    }
}
